// 自定义Hook

import { findCityApi, findCountryApi } from "@/apis/countryApi";
import { findOrganizationTypesApi } from "@/apis/organizationTypeApi";
import { findWorkplaceApi } from "@/apis/workplaceApi";
import { useState } from "react";

const useFindData = () => {

    const [countryData, setCountryData] = useState([]);
    const [cityData, setCityData] = useState([]);
    const [organizationTypeData, setOrganizationType] = useState({
        rows: [],
        total: 0
    });
    const [workplaceData, setWorkplaceData] = useState({
        rows: [],
        total: 0
    });
    // 获取国家数据
    const findCountryHook = async () => {
        const res = await findCountryApi();
        if (res.code == 200) {
            setCountryData(res.data);
        }
    }
    // 获取城市数据
    const findCityHook = async (data: { name: string }) => {
        const res = await findCityApi(data);
        if (res.code == 200) {
            setCityData(res.data);
        }
    }
    // 获取组织类型
    const findOrganizationTypeHook = async (data?: object) => {
        const res = await findOrganizationTypesApi(data);
        if (res.code == 200) {
            setOrganizationType(res.data);
        }
    }
    // 获取工作地点
    const findWorkplaceHook = async (data?: object) => {
        const res = await findWorkplaceApi(data);
        if (res.code == 200) {
            setWorkplaceData(res.data);
        }
    }


    return {
        findCountryHook, countryData,
        findCityHook, cityData,
        findOrganizationTypeHook, organizationTypeData,
        findWorkplaceHook, workplaceData
    }
}


export default useFindData;